﻿using FlyIL.Trace;

namespace FlyIL.Optimizer;

class PushPass : SimplfyRoot
{


    public override bool IsMatch(Context con, Inst node, ExpByTrace expression = null)
        => (node.Opt == Opt.push);

    /// <summary>
    ///  push 的情况 
    /// </summary>
    public override void Do(Context con, Inst node, ExpByTrace expression = null)
    {
        var inst = node;
        var exp = con.TraceStrict(node, ref inst.O1);

        if (exp == null || !exp.IsValid)
            return;

        if (exp.Calculable)
            inst.O1 = Operand.Make(exp.Result, inst.O1.ByteSize);
        else if (exp.CalcDepth == 0)
            inst.O1 = exp.FinalLeft<Operand>();
    }
}

